home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / sc3x04.exe / GETLOCK.C < prev    next >
Text File  |  1993-08-02  |  6KB  |  150 lines

  1. //   ╔════════════════════════════════════════════════════════════════════╗
  2. //   ║                                                                    ║
  3. //   ║ module:      3xsc.c                                                ║
  4. //   ║ abstract:    This module shows how to make 3.x system calls using  ║
  5. //   ║              the F2 Shell Interface.  Obviously, it requires the   ║
  6. //   ║              NetWare Shell.                                        ║
  7. //   ║                                                                    ║
  8. //   ║ environment: NetWare 3.x v3.11                                     ║
  9. //   ║              Borland C++ 3.1                                       ║
  10. //   ║                                                                    ║
  11. //   ║  This software is provided as is and carries no warranty           ║
  12. //   ║  whatsoever.  Novell disclaims and excludes any and all implied    ║
  13. //   ║  warranties of merchantability, title and fitness for a particular ║
  14. //   ║  purpose.  Novell does not warrant that the software will satisfy  ║
  15. //   ║  your requirements or that the software is without defect or error ║
  16. //   ║  or that operation of the software will be uninterrupted.  You are ║
  17. //   ║  using the software at your risk.  The software is not a product   ║
  18. //   ║  of Novell, Inc. or any of subsidiaries.                           ║
  19. //   ║                                                                    ║
  20. //   ║      ****    NOTICE    ****    NOTICE   ****   NOTICE   ****       ║
  21. //   ║                                                                    ║
  22. //   ║  This example code has not been extensively tested and therefore   ║
  23. //   ║  should be run on a test server before used in a production en-    ║
  24. //   ║  vironment.  Also, a backup is recommended before the installation ║
  25. //   ║  of any untested component.                                        ║
  26. //   ║                                                                    ║
  27. //   ╚════════════════════════════════════════════════════════════════════╝
  28.  
  29. #include <conio.h>
  30. #include <io.h>
  31. #include <stdio.h>
  32. #include <string.h>
  33. #include <stdlib.h>
  34. #include <dos.h>
  35. #include "nwsys.h"
  36. #include <share.h>
  37. #include <fcntl.h>
  38. #include <sys/stat.h>
  39.  
  40. //
  41. //  First of all, we define the request and reply structures which are
  42. //  needed for the ScanConnectionsUsingFile API call.  These structures are
  43. //  layed out according to the System Call documentation.
  44. //
  45.  
  46. struct  {
  47.      WORD   sflen;          // length of the structure
  48.      BYTE   sfcode;         // the subfunction code
  49.      BYTE   dataStreamNum;  // name space
  50.      BYTE   volumeNumber;   // volume number
  51.      LONG   directoryEntry; // dirEntry sequence number
  52.      WORD   nextRequest;    // last record
  53. } Request;
  54.  
  55. typedef struct {
  56.     WORD    loggedCount;    // tasks that have record logged
  57.     WORD    shareLockCount; // tasks that have record locked sharable
  58.     LONG    recordStart;    // byte offset where record begins
  59.     LONG    recordEnd;      // byte offset where record ends
  60.     WORD    connNumber;     // logical connection number with exclusive lock
  61.     WORD    taskNumber;     // task numbrt with exclusive lock
  62.     BYTE    lockType;
  63. } LOCK_INFO;
  64.  
  65. struct {
  66.     WORD     nextRequest;       // next record
  67.     WORD    numberOfLocks;
  68.     LOCK_INFO
  69.             lockInfo[70];      // individual connection info
  70. } Reply;
  71.  
  72. //
  73. //  This is the main program.  The purpose is to make the ScanConnections
  74. //  UsingFiles API call to illustrate making system calls using the F2
  75. //  interface.
  76. //
  77.  
  78. int ConvertPathToDirEntry(char *path, BYTE *volume, LONG *dirEntry);
  79.  
  80. int main(int argc, char *argv[])
  81. {
  82.     int   cc;
  83.     char    dirPath[255];
  84.     BYTE    volumeNumber;
  85.     LONG    sequenceNumber;
  86.     int    fileHandle;
  87.  
  88.     if(argc!=2) {
  89.         printf("usage: getlock FullPath\n");
  90.         exit(1);
  91.     }
  92.     strcpy(dirPath,argv[1]);
  93.     fileHandle=sopen(dirPath, O_TEXT, SH_DENYNO);
  94.     if(fileHandle == -1) {
  95.         printf("\nUnable to open %s.",dirPath);
  96.         exit(1);
  97.     }
  98.     //
  99.     //  Build the request buffer
  100.     //
  101.     cc=ConvertPathToDirEntry(dirPath, &volumeNumber, &sequenceNumber);
  102.     if( cc ) {
  103.         printf("%s not Found.",dirPath);
  104.         exit(1);
  105.     }
  106.     Request.sflen = (sizeof Request) ;
  107.     Request.sfcode = 238;                       // subfunction code
  108.     Request.dataStreamNum = 0;
  109.     Request.volumeNumber = volumeNumber;
  110.     Request.directoryEntry = sequenceNumber;
  111.     Request.nextRequest = 0;
  112.     cc = NWSystemCall(23,&Request,sizeof Request,&Reply,sizeof Reply);
  113.     printf("Function returned:    %03d--%#02x\n",cc,cc);
  114.     printf("Number of locks = %d\n", Reply.numberOfLocks);
  115.     printf("\nPress any key to close file!");
  116.     getch();
  117.     close(fileHandle);
  118.     return 0;
  119. }
  120.  
  121. int ConvertPathToDirEntry(char *path, BYTE *volume, LONG *dirEntry)
  122. {
  123.     static struct {
  124.         WORD  sflen;             // length of the structure
  125.         BYTE  sfcode;            // the subfunction code
  126.         BYTE  dirHandle;         // type of file
  127.         BYTE  pathStringLength;  // length of path
  128.         BYTE  pathString[255];   // path
  129.     } dirEntryRequest;
  130.  
  131.    static struct {
  132.         BYTE    volumeNumber;   // volume number
  133.         LONG    dirEntry;       // directory entry sequence
  134.     } dirEntryReply;
  135.     int    cc;
  136.  
  137.     dirEntryRequest.sflen=sizeof(dirEntryRequest);
  138.     dirEntryRequest.sfcode=0xF4;
  139.     dirEntryRequest.dirHandle=0x00;
  140.     dirEntryRequest.pathStringLength=strlen(path);
  141.     memcpy(&dirEntryRequest.pathString,path,strlen(path));
  142.     cc = NWSystemCall(23,&dirEntryRequest,sizeof dirEntryRequest,&dirEntryReply,sizeof dirEntryReply);
  143.     if( !cc) {
  144.         *volume=dirEntryReply.volumeNumber;
  145.         *dirEntry=dirEntryReply.dirEntry;
  146.     }
  147.     return( cc );
  148. }
  149. 
  150.